import { System, World } from '@ecs/index'
import { Score, Text } from '../components'

/**
 * 计分系统
 * @description 计算游戏得分
 */
export class ScoreSystem extends System {
  constructor() {
    super()
  }

  public update(world: World): void {
    const score = world.findNameWithEntities('score')[0]
    if (!score) {
      return
    }
    const componentMap = world.findEntityWithComponents(score)
    const text = componentMap.get(Text)
    const gameScore = componentMap.get(Score)
    text.text = `【ECS实现】得分:${gameScore.gameScore++}`
  }

  public destory(): void {}
}
